package com.biodiv.miracle.web.interceptor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author: tianquan
 * @date: 2025-05-28  10:33
 * @description: 拦截器注册类
 */
public class InterceptorRegistration {

    private final HandlerInterceptor interceptor;
    private final List<String> excludePatterns = new ArrayList<>();
    private int order = 0;

    public InterceptorRegistration(HandlerInterceptor interceptor) {
        this.interceptor = interceptor;
    }

    public InterceptorRegistration excludePathPatterns(String... patterns) {
        return this.excludePathPatterns(Arrays.asList(patterns));
    }

    public InterceptorRegistration excludePathPatterns(List<String> patterns) {
        this.excludePatterns.addAll(patterns);
        return this;
    }

    public InterceptorRegistration order(int order) {
        this.order = order;
        return this;
    }

    protected int getOrder() {
        return this.order;
    }

    protected HandlerInterceptor getRegistrationBean() {
        return this.interceptor;
    }

    public HandlerInterceptor match(String pattern){
        // 当前url是否排除
        if (excludePatterns.contains(pattern)) {
            return null;
        }
        return interceptor;
    }

}
